package com.yixun.dy.controller;

import com.yixun.controller.BaseController;
import com.yixun.dy.entity.YxProTransport;
import com.yixun.dy.service.YxProTransportService;
import com.yixun.entity.YxRole;
import com.yixun.entity.YxUser;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

@Controller
@RequestMapping(value = "/tran")
public class YxProTransportController extends BaseController {

    @Autowired
    private  YxProTransportService yxProTransportService;

    /**=============================调出====================**/

    /**
     * 跳转调出页面
     */
    @RequestMapping(value = "/list")
    public String list(Model model){

        return "org/dy/list_out";
    }


    /**
     * 列表页面
     */
    @RequestMapping(value = "/getTranList")
    @ResponseBody
    public List<YxProTransport> getTranList(@RequestBody Map<String, String> map){
        map.put("dy_type","调出");
        return yxProTransportService.getListByPage(map);
    }

    /**
     * 获取调运总数据
     */
    @RequestMapping(value = "/getTranCount")
    @ResponseBody
    public Integer getTranCount(){
        return yxProTransportService.getTranCount("调出");
    }


    @RequestMapping(value = "/go_add")
    public String tran_add(String tran_id, Model model){
        model.addAttribute("tran_id",tran_id);
        return "org/dy/tran_add";
    }

    /**
     * 根据id获取对象
     */
    @RequestMapping(value = "/getTranBean/{id}")
    @ResponseBody
    public YxProTransport getTranBean(@PathVariable(value = "id") String id){
        return yxProTransportService.getYxProTransport(id);
    }

    /**
     * 添加
     */
    @RequestMapping(value = "/add", method = RequestMethod.POST)
    @ResponseBody
    public boolean add(@RequestBody Map<String, String> map){
        int row = yxProTransportService.insertYxProTransport(this.getSessionUser(),map);
        return row == 1;
    }

    /**
     * 删除
     */
    @RequestMapping(value = "/del", method = RequestMethod.POST)
    @ResponseBody
    public boolean del(@RequestBody Map map){
        int row = yxProTransportService.delTran(map);
        return row > 0;
    }

    /**=============================调入====================**/
    /**
     * 跳转调出页面
     */
    @RequestMapping(value = "/listin")
    public String listin(Model model){
        return "org/dy/list_in";
    }

    /**
     * 列表页面
     */
    @RequestMapping(value = "/getTranListin")
    @ResponseBody
    public List<YxProTransport> getTranListin(@RequestBody Map<String, String> map){
        map.put("dy_type","调入");
        return yxProTransportService.getListByPage(map);
    }

    /**
     * 获取调运总数据
     */
    @RequestMapping(value = "/getTraninCount")
    @ResponseBody
    public Integer getTraninCount(){
        return yxProTransportService.getTranCount("调入");
    }

    @RequestMapping(value = "/goin_add")
    public String tranin_add(String tran_id, Model model){
        model.addAttribute("tran_id",tran_id);
        return "org/dy/tranin_add";
    }
}
